package manipulacaoarquivos

class ManipulacaoController {

   def index() {

		def file = readFile()

		def lines = []

		file.eachLine { line -> 
			lines << line 
			}

		def linesHtml = listToTable(lines)

		render "<h2>Bazinga!</h2>" + linesHtml
	}

	private def readFile(){

		new File("""web-app//clientes.txt""");
	}

	private def listToUl = { list ->

		def retorno = "<ul>"

		list.collect{ item -> "<li>" + item + "</li>" }.each {
			retorno += it 
		}

		retorno += "</ul>"
	}
	
	private def listToTable = {  lines ->
		
		def retorno = "<table border='1'>"
		
		retorno += lines.collect{ line ->
		
			"<tr>"+
				line.split(";").collect{"<td>"+ it + "</td>"}.join()+ 
			"</tr>"	
			
		}.join()
		
		return retorno + "</table>"
		
	}
}
